package de.baumann.browser.model;


import java.util.List;

import de.baumann.browser.api.net.util.LicenceHttpUtil;
import de.baumann.browser.api.net.vo.Licence;
import de.baumann.browser.api.net.vo.LoginInfo;
import de.baumann.browser.api.net.vo.Rank;
import de.baumann.browser.api.net.vo.Result;
import de.baumann.browser.api.net.vo.Transfer;
import de.baumann.browser.api.net.vo.UseableCount;
import de.baumann.browser.rx.RxSchedulers;
import de.baumann.browser.utils.UserDataKt;
import io.reactivex.Observable;

public class LicenceModel extends BaseModel {

    /**
     * 获取未激活的Licence
     *
     * @return
     */
    public Observable<Result<List<Licence>>> getInactivatedLicences() {
        LoginInfo localUser = UserDataKt.getUser();
        if (localUser == null) {
            return Observable.just(new Result("数据异常", -2));
        }
        return LicenceHttpUtil.Companion.licences().compose(RxSchedulers.ioMain());
    }


    public Observable<Result<Object>> licenceActive(String licenceId) {
        return LicenceHttpUtil.Companion.licenceActive(licenceId).compose(RxSchedulers.ioMain());
    }

    public Observable<Result<Object>> licenceGift(String licenceId, String toLoginName) {
        return LicenceHttpUtil.Companion.licenceGives(licenceId, toLoginName).compose(RxSchedulers.ioMain());
    }

    public Observable<Result<String>> odinAddress(String addr) {
        return LicenceHttpUtil.Companion.odinAddresss(addr).compose(RxSchedulers.ioMain());
    }

    public Observable<Result<Object>> getTransThorAddress(String odinAddress, String thorAddress,
                                                          String remark,
                                                          String remark1,
                                                          String remark2,
                                                          String remark3,
                                                          String remark4,
                                                          String remark5) {
        return LicenceHttpUtil.Companion.getTransThorAddress(odinAddress, thorAddress, remark, remark1, remark2, remark3, remark4, remark5).compose(RxSchedulers.ioMain());
    }

    public Observable<Result<List<Transfer>>> transList() {
        return LicenceHttpUtil.Companion.transList().compose(RxSchedulers.ioMain());
    }

    public Observable<Result<LoginInfo>> getFreeLicence() {
        return LicenceHttpUtil.Companion.getFreeLicence().compose(RxSchedulers.ioMain());
    }

    public Observable<Result<UseableCount>> getLicenceCount() {
        return LicenceHttpUtil.Companion.getLicenceCount().compose(RxSchedulers.ioMain());
    }


    public Observable<Result<List<Rank>>> getLicenceRank() {
        return LicenceHttpUtil.Companion.getRank().compose(RxSchedulers.ioMain());
    }


}
